<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta charset="utf-8">
  <title>测试php get和post方法</title>
  <script type="text/javascript" src="js/sha1.js"></script>
</head>

<body>
  <form class="regForm" action="server/reg.php" method="post">
    <input type="text" name="username" value="" placeholder="请输入用户名">
    <input type="password" name="password" value="" placeholder="请输入密码">
    <input type="submit" name="" value="注册">
  </form>
</body>

<script type="text/javascript">
  /**
   * 用户点击注册按钮时，对用户提交的密码进行hash后提交
   */
  var form = document.getElementsByClassName('regForm')[0];
  form.addEventListener('submit', function(event) {
    var password = (document.getElementsByName('password')[0]);
    password.value = hex_sha1(password.value);
    // alert('hash之后的密码为: ' + password.value);
    form.submit();
  });
</script>

</html>